package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author:石小俊
 * @Date:2022/12/12 9:05
 * @Version:1.0-SNAPSHOT
 * @Description:
 */
@WebServlet("/rm")
public class RequestMethodServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String servletPath = request.getServletPath();
        System.out.println("浏览器地址栏应用名后面的地址:"+servletPath);

        String contextPath = request.getContextPath();
        System.out.println("应用名:"+contextPath);

        // uri:浏览器地址栏端口号后面的地址
        String uri = request.getRequestURI();
        System.out.println("uri:"+uri);

        // url:获取浏览器地址栏完整的URL地址
        String url = request.getRequestURL().toString();
        System.out.println("url:"+url);

        // 获取访问者的ip地址
        String ip = request.getRemoteAddr();
        System.out.println("访问者的ip:"+ip);
    }

}
